package com.jungle.app.jw.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;

import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.jungle.common.annotation.RepeatSubmit;
import com.jungle.common.core.controller.BaseController;
import com.jungle.common.core.domain.PageQuery;
import com.jungle.common.core.domain.R;
import com.jungle.common.core.validate.AddGroup;
import com.jungle.common.core.validate.EditGroup;
import com.jungle.app.jw.domain.vo.JwSpotFacilityVo;
import com.jungle.app.jw.domain.bo.JwSpotFacilityBo;
import com.jungle.app.jw.service.IJwSpotFacilityService;
import com.jungle.common.core.page.TableDataInfo;

/**
 * 景点设施
 *
 * @author jungle
 * @date 2023-12-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/jw/spotFacility")
public class JwSpotFacilityController extends BaseController {

    private final IJwSpotFacilityService iJwSpotFacilityService;

    /**
     * 查询景点设施列表
     */
    @GetMapping("/list")
    public TableDataInfo<JwSpotFacilityVo> list(JwSpotFacilityBo bo, PageQuery pageQuery) {
        return iJwSpotFacilityService.queryPageList(bo, pageQuery);
    }
    /**
     * 导入景点设施列表
     */
    /**
     * 导出景点设施列表
     */

    /**
     * 获取景点设施详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<JwSpotFacilityVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iJwSpotFacilityService.queryById(id));
    }

    /**
     * 新增景点设施
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody JwSpotFacilityBo bo) {
        return toAjax(iJwSpotFacilityService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改景点设施
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody JwSpotFacilityBo bo) {
        return toAjax(iJwSpotFacilityService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除景点设施
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iJwSpotFacilityService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

}
